package test.visualtests;
/* Java Version 1.4.2_03-b02
 *
 * |-------------------------------------------------------------------|
 * |        |             Name              |         Language         |
 * |        |-------------------------------|--------------------------|
 * |  SNo.  |       |        Second         |        |      Others     |
 * |        | First |-----------------------| Native |-----------------|
 * |        |       |   1   |    2   |      |   2    |   3    |        |
 * |-------------------------------------------------------------------|
 * |        |       |       |        |      |        |        |        |
 *
 */


import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;
import javax.swing.table.DefaultTableModel;

import table.MultiLineTable;
import table.model.ColumnGroup;
import table.model.SimpleColumn;
import table.view.multirowheader.GroupableTableColumnModel;


/**
 * 
 * @author D'Er'Nasherbrezon aka dernasherbrezon %)
 *
 */
public class GroupableColumnExample extends JFrame {
    
    GroupableColumnExample() {
        super( "Multi-Width Header Example" );
        
        DefaultTableModel dm = new DefaultTableModel();
        dm.setDataVector(new Object[][]{
            {"119","Finbar", "John","Saunders","ja","ko","zh"},
            {"911","Roger", "Peter","Melly","en","fr","pt"}},
            new Object[]{"SNo.","First", "1","2","Native","2","3"});
            
            // Setup table
            MultiLineTable table = new MultiLineTable(dm);
            GroupableTableColumnModel         cm = new GroupableTableColumnModel();
            
            for(int i=0;i<dm.getColumnCount();i++)
            {
                SimpleColumn Column0 = new SimpleColumn(i,dm.getColumnName(i));
                cm.addColumn(Column0);
            }
            
            // Setup Column Groups
            ColumnGroup name = new ColumnGroup("Name");
            ColumnGroup group2 = new ColumnGroup("Group2");
            group2.add(cm.getColumn(1));
            group2.add(cm.getColumn(2));
            
            ColumnGroup group = new ColumnGroup("Group");
            group.add(cm.getColumn(3));
            group.add(cm.getColumn(4));
            
            name.add(group2);
            name.add(group);

            cm.addColumnGroup(name);
            
            
            
table.setColumnModel(cm);
table.fireTableStructureChanged();

            // Finish off gui
            //JScrollPane scroll = new JScrollPane( table );
            getContentPane().add( table );
            setSize( 800, 200 );
    }
    
    public static void main(String[] args) 
    {
        GroupableColumnExample frame = new GroupableColumnExample();
        frame.addWindowListener( new WindowAdapter()
        {
            public void windowClosing( WindowEvent e )
            {
                System.exit(0);
            }
        });
        frame.setVisible(true);
    }
}

